package com.ngc.mall.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ngc.mall.common.configure.LocalUser;
import com.ngc.mall.common.configure.mybatisPlus.BaseServiceImpl;
import com.ngc.mall.core.enumeration.MessageStatus;
import com.ngc.mall.domain.MessageRecordDomain;
import com.ngc.mall.mapper.MessageRecordMappper;
import com.ngc.mall.service.IMessageRecordService;
import com.ngc.mall.vo.MessageRecordVO;
import com.ngc.mall.vo.PagingVO;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * 消息接收实现类
 * @author: chenxiaolin
 * @date 2023/11/8 15:03
**/
@Service
public class MessageRecordServiceImpl extends BaseServiceImpl<MessageRecordMappper, MessageRecordDomain> implements IMessageRecordService {

    @Override
    public Boolean createMessageRecord(MessageRecordDomain domain){
        return super.save(domain);
    }

    @Override
    public Boolean updateStatusToReadById(Long id){
        LocalDateTime now=LocalDateTime.now();
        return super.update(Wrappers.<MessageRecordDomain>lambdaUpdate().eq(MessageRecordDomain::getId,id).set(MessageRecordDomain::getStatus, MessageStatus.READ.getValue()).set(MessageRecordDomain::getReadTime,now));
    }

    @Override
    public Boolean deleteById(Long id){
        return super.removeById(id);
    }

    @Override
    public List<MessageRecordVO> getNoticeByMySelf(){
        Long uid=LocalUser.getLocalUser().getId();
        return baseMapper.getAllNoticeByMySelf(uid);
    }

    @Override
    public List<MessageRecordVO> getSingleChatByMySelf(){
        Long uid=LocalUser.getLocalUser().getId();
        return baseMapper.getAllSingleChartByMySelf(uid);
    }
}
